package com.pk.platform.util;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;

public class WebUtil {

	/**
     * <p>
     * 说明:dwr request
     * </p>
     * @return
     */
    public static HttpServletRequest getDwrRequest()
    {
        WebContext web = WebContextFactory.get();
        HttpServletRequest request = web.getHttpServletRequest();
        return request;
    }
    
    /**
     * <p>
     * 说明:dwr response
     * </p>
     * @return
     */
    public static HttpServletResponse getDwrResponse()
    {
        WebContext web = WebContextFactory.get();
        HttpServletResponse response = web.getHttpServletResponse();
        return response;
    }
    
    /**
     * <p>
     * 说明:dwr session
     * </p>
     * @return
     */
    public static HttpSession getDwrSession()
    {
        HttpServletRequest request = getDwrRequest();
        return request.getSession();
    }
    
    
    /**
     * <p>
     * 说明:组装列表
     * </p>
     * @param str[0]:显示  str[1]:值
     * @return
     */
    public static List<SelectOption> constructOptions(String[][] str)
    {
        List<SelectOption> list = new ArrayList<SelectOption>();
        int len = str.length;
        if(len < 2)
        {
            return null;
        }
        int len2 = str[0].length;
        for(int j = 0; j < len2; j++)
        {
            SelectOption so = new SelectOption(str[0][j], str[1][j]);
            list.add(so);
        }
        return list;
    }
	
}
